#include "camera.h"
#include "scene.h"

#include <iostream>

namespace rt {

Camera::Camera()
    : m_position(0.0,0.0,0.0)
    , m_direction(0.0,0.0,1.0)
    , m_view_angles(std::make_pair<double,double>(80.0,60.0))
    , m_film()
{

}

Camera::~Camera()
{

}

void Camera::render(const Scene &a_scene)
{
    std::size_t j(0), i(0);
    Vector a_direction(0.0,0.0,1.0);

    double dx(1.0 / static_cast<double>(m_film.width()));
    double dy(1.0 / static_cast<double>(m_film.height()));

    std::vector<Color>::iterator l_it(m_film.begin());
    for(j=0; j < m_film.height(); ++j) {
        for(i=0; i < m_film.width(); ++i,++l_it) {

            a_direction = m_z + m_x*(i*dx+dx/2.0) + m_y*(j*dy+dy/2.0);

            Ray a_ray(*l_it,m_position,a_direction);
            a_scene.render(a_ray);
        }
    }
}


void Camera::mRecomputeCameraBase()
{
    m_z = m_direction;
    m_z.normalize();

    m_y = Vector(0.0,1.0,0.0);

    m_x = m_y^m_z;
    m_x.normalize();

    m_y = m_z^m_x;
    m_y.normalize();
}

} //end of namespace
